package com.zhku.zhny.user.web.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zhku.zhny.admin.service.AdminService;
import com.zhku.zhny.admin.service.AdminServiceImpl;
import com.zhku.zhny.domain.SignUp;
import com.zhku.zhny.util.RandomIdFactory;

@WebServlet("/user/signUp")
public class UserServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	/**
	 * 报名
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void signUp(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SignUp signUp = new SignUp();
		// 封装数据
		signUp.setId(RandomIdFactory.getRandomId());
		signUp.setName(request.getParameter("username"));
		signUp.setGender(request.getParameter("gender"));
		signUp.setClasses(request.getParameter("class"));
		signUp.setGroupName(request.getParameter("majorGroup"));
		signUp.setTelephone(request.getParameter("phone"));
		signUp.setIntroduction(request.getParameter("introduction"));
		try {
			AdminService adminService = new AdminServiceImpl();
			int result = adminService.addSignUpInfo(signUp);
			if(result>0) {
				response.getWriter().print("true");
			}else {
				response.getWriter().print("false");
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.getWriter().print("false");
		}
	}
}
